package com.yn.xgame.logic;

import java.sql.Connection;
import java.sql.DriverManager;

import org.apache.commons.dbutils.QueryRunner;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.yn.xgame.DBHandler;
import com.yn.xgame.IFuncServerLike;
import com.yn.xgame.ThreadServer;
import com.yn.xgame.logic.handler.BankTransactionHandler;
import com.yn.xgame.logic.handler.DbLoadHandler;
import com.yn.xgame.logic.handler.DumpHander;
import com.yn.xgame.logic.handler.LoginHandler;
import com.yn.xgame.logic.handler.RegistHandler;
import com.yn.xgame.logic.handler.UserBaseInfoHandler;

/**
 * DbServer
 * Created by wangboo on 17/7/13.
 */
public class DbServer extends ThreadServer implements IFuncServerLike {

    private static final Logger logger = LoggerFactory.getLogger(DbServer.class);
    private DBHandler handler;
    private Connection conn;
    private QueryRunner runner;
    
    LoginHandler loginHandler;
    RegistHandler registHandler;
    DbLoadHandler dbLoadHandler;
    UserBaseInfoHandler userBaseInfoHandler;
    BankTransactionHandler bankTransactionHandler;
    DumpHander dumpHander;
    public DbServer() throws Exception {
        super("LogicDbServer");
        Class.forName(LogicApp.config.getDbDriver());
        conn = DriverManager.getConnection(LogicApp.config.getDbUrl());
        runner = new QueryRunner();

        handler = new DBHandler() {
            @Override
            public Logger logger() {
                return logger;
            }
        };
        loginHandler=new LoginHandler(runner,conn);
        registHandler=new RegistHandler(runner,conn);
        dbLoadHandler=new DbLoadHandler(runner,conn);
        userBaseInfoHandler=new UserBaseInfoHandler(runner,conn);
        bankTransactionHandler= new BankTransactionHandler(runner, conn);
        dumpHander= new DumpHander(runner, conn);
    }
}
